package com.zy.web.controller.bs;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.zy.entity.bs.Bbs;
import com.zy.pojo.query.bs.BbsQuery;
import com.zy.pojo.vos.common.PageVo;
import com.zy.pojo.vos.common.ResultVo;
import com.zy.service.bs.BbsService;
import com.zy.web.controller.base.BaseController;
import com.zy.web.utils.ResultUtil;

@RequestMapping({"bs/bbs","m/bs/bbs"})
@Controller
public class BbsController extends BaseController {

	@Autowired
	private BbsService bbsService;

	/**
	 * 分页
 	 * 
 	 * @param bbsQuery
	 * @param start
	 * @param limit
	 * @return
	 */
	@RequestMapping("pageBbs")
	@ResponseBody
	public PageVo pageBbs(BbsQuery bbsQuery, Integer start, Integer limit) {
		return this.bbsService.pageBbs(bbsQuery, start, limit);
	}

	/**
	 * 新增
	 * 
	 * @param bbs
	 * @return
	 */
	@RequestMapping(value = "saveBbs", method = RequestMethod.POST)
	@ResponseBody
	public ResultVo saveBbs(Bbs bbs) {
		try {
			this.bbsService.saveBbs(bbs);
			return ResultUtil.success();
		} catch (Exception e) {
			return ResultUtil.error(log, e);
		}
	}
	
	/**
	 * 更新
	 * 
	 * @param bbs
	 * @return
	 */
	@RequestMapping(value = "updateBbs", method = RequestMethod.POST)
	@ResponseBody
	public ResultVo updateBbs(Bbs bbs) {
		try {
			this.bbsService.updateBbs(bbs);
			return ResultUtil.success();
		} catch (Exception e) {
			return ResultUtil.error(log, e);
		}
	}

	/**
	 * 删除
	 * 
	 * @param id
	 * @return
	 */
	@RequestMapping(value = "removeBbs", method = RequestMethod.POST)
	@ResponseBody
	public ResultVo removeBbs(long id) {
		try {
			this.bbsService.removeBbs(id);
			return ResultUtil.success();
		} catch (Exception e) {
			return ResultUtil.error(log, e);
		}
	}

	/**
	 * 恢复
	 * 
	 * @param id
	 * @return
	 */
	@RequestMapping(value = "recover", method = RequestMethod.POST)
	@ResponseBody
	public ResultVo recover(long id) {
		try {
			this.bbsService.recover(id);
			return ResultUtil.success();
		} catch (Exception e) {
			return ResultUtil.error(log, e);
		}
	}
	@RequestMapping("appBBs")
	@ResponseBody
	public PageVo appBBs(BbsQuery bbsQuery, Integer start, Integer limit) {
		return this.bbsService.appBbs(bbsQuery, start, limit);
	}

	@RequestMapping("getBbsInfo")
	@ResponseBody
	public ResultVo getBbsInfo(Long id) {
		try {
			return ResultUtil.success(this.bbsService.getByPrimaryKey(id));
		} catch (Exception e) {
			return ResultUtil.error(log, e);
		}
	}

}